/*****************************************************************************************
Arise Engine		ToolsView.cpp

					E-mail:		arise_engine@mail.ru

created:			17.03.2007
last changes:		24.04.2007

ToolsView.cpp : implementation of the ToolsView class

Project is an MFC application, using the single-document model, split-window style.
Based on EffectEdit Direct3D Sample (c) Microsoft Corporation. All rights reserved.
*****************************************************************************************/
#include "stdafx.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#define TOOLS_VIEW_WIDTH	200
#define PAGE_START_X	0
#define PAGE_START_Y	30
#define PAGE0_TITLE		""//"tab0"
#define PAGE1_TITLE		""//"tab1"
#define PAGE_ICON_SIZE	16

HWND g_hwnd_tools_view;


// ToolsView
IMPLEMENT_DYNCREATE(ToolsView, CFormView)
BEGIN_MESSAGE_MAP(ToolsView, CFormView)
    //{{AFX_MSG_MAP(CToolsView)
    ON_WM_SIZE()
	ON_NOTIFY(TCN_SELCHANGE, IDC_TOOLS_TAB, OnTcnSelchangeToolsTab)
   //}}AFX_MSG_MAP
END_MESSAGE_MAP()



ToolsView::ToolsView(): CFormView(ToolsView::IDD)
{
	m_current_page = -1;
}
ToolsView::~ToolsView()
{
}


void ToolsView::DoDataExchange(CDataExchange* pDX)
{
	g_hwnd_tools_view = GetSafeHwnd();
	
	CFormView::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CErrorsView)
	DDX_Control(pDX, IDC_TOOLS_TAB, m_tab_list);
    //}}AFX_DATA_MAP
}


void ToolsView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	m_image_list.Create(PAGE_ICON_SIZE, PAGE_ICON_SIZE, ILC_COLOR32, 0, 0); 

	CBitmap		bitmap;
	COLORREF	color_ref = 1;

	HBITMAP hBitmap = (HBITMAP)::LoadImage(		AfxGetInstanceHandle(),
												MAKEINTRESOURCE(IDB_BITMAP_TOOLS_ICONS), 
												IMAGE_BITMAP, 
												0, 
												0,
												LR_COPYFROMRESOURCE | LR_CREATEDIBSECTION
											);	
	bitmap.Detach();
	bitmap.Attach(hBitmap); 

	m_image_list.Add(&bitmap, color_ref);
	m_tab_list.SetImageList(&m_image_list);


	TC_ITEM tab_item;

	tab_item.mask		= TCIF_TEXT | TCIF_IMAGE;
	tab_item.iImage		= 0; 
	tab_item.pszText	= PAGE0_TITLE;
	m_tab_list.InsertItem(0, &tab_item);	
	
	tab_item.mask		= TCIF_TEXT | TCIF_IMAGE;
	tab_item.iImage		= 1; 
	tab_item.pszText	= PAGE1_TITLE;
	m_tab_list.InsertItem(1, &tab_item);	

	VERIFY(pPage0.Create(IDD_TOOLS0_DIALOGBAR, &m_tab_list));
	pPage0.SetWindowPos(NULL, PAGE_START_X, PAGE_START_Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);	

	VERIFY(pPage1.Create(IDD_TOOLS1_DIALOGBAR, &m_tab_list));
	pPage1.SetWindowPos(NULL, PAGE_START_X, PAGE_START_Y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);

	ApplyCurrentPage(0);



}


// ToolsView diagnostics

#ifdef _DEBUG
void ToolsView::AssertValid() const
{
	CFormView::AssertValid();
}

void ToolsView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG


// ToolsView message handlers

void ToolsView::OnSize(UINT nType, int cx, int cy) 
{
	SetScrollSizes( MM_TEXT, CSize(cx, cy) );
    CFormView::OnSize(nType, cx, cy);
  
    CWnd* pToolsTab = GetDlgItem(IDC_TOOLS_TAB);
    if(pToolsTab) pToolsTab->SetWindowPos(NULL, 0, 0, TOOLS_VIEW_WIDTH, cy, SWP_NOZORDER);
}


void ToolsView::OnTcnSelchangeToolsTab(NMHDR *pNMHDR, LRESULT *pResult)
{
	*pResult = 0;

	UINT current_tab = m_tab_list.GetCurFocus();

	ApplyCurrentPage(current_tab);
}


void ToolsView::HideAllPages()
{
	pPage0.ShowWindow(SW_HIDE);
	pPage1.ShowWindow(SW_HIDE);
}


void ToolsView::ApplyCurrentPage(UINT page)
{
	HideAllPages();

	switch(page)
	{
		case 0: pPage0.ShowWindow(SW_SHOW); break;
		case 1: pPage1.ShowWindow(SW_SHOW); break;

		default: m_current_page = -1; return;	// error
	}

	m_tab_list.SetCurSel(page);
	m_current_page = page;
}

